
import Macro from '../Macro';
import { MLAgentsSettings } from './MLAgentsSettings';

export class MLAgentsSettingsManager {

    static onSettingsChanged: () => void = null!;

    static _settings: MLAgentsSettings = null!;

    static get settings(): MLAgentsSettings {

        if (this._settings == null) {
            this.initialize();
        }

        return this._settings;
    }

    static set settings(value: MLAgentsSettings) {
        this._settings = value;
        this.applySettings();
    }


    static async initialize() {
        if (Macro.CCC_EDITOR) {
            this._settings = new MLAgentsSettings();
            this._settings.connectTrainer = await Editor.Profile.getProject('mlagents', 'connectTrainer');
            this._settings.editorTrainingPort = await Editor.Profile.getProject('mlagents', 'editorTrainingPort');
            this._settings.editorProxyPort = await Editor.Profile.getProject('mlagents', 'editorProxyPort');
        }else{
            this._settings = new MLAgentsSettings();
            this._settings.connectTrainer = true;
            this._settings.editorTrainingPort = 5004;
            this._settings.editorProxyPort = 5050;
        }

    }

    static applySettings() {
        this.onSettingsChanged?.();
    }


}

MLAgentsSettingsManager.initialize();